﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using System.IO;

public partial class admin_manager_static_pub_list : AdminBasePage
{
    public IList datalist = new ArrayList();
    public string columnId;
    public string eName;
    public string dpath;
    public string fileName;
    public string url;
    public string allpath;
    public string orderId;
    private string layerid;
    protected void Page_Load(object sender, EventArgs e)
    {
        //if(!IsPostBack)
        {
            //权限判断
            //PopedomValidate(Layerid, QUERY);
            string cid = Request.Params["columnid"];
            ColumnBll cbll = new ColumnBll();
            ColumnModel cm = cbll.GetColumn(int.Parse(cid));
            layerid = cm.Layerid;
            if (cid != null && cid != ""
                && layerid != null && layerid != ""
                )
            {

                datalist = cbll.GetColumnList(int.Parse(cid));
                for (int i = 0; i < datalist.Count; i++)
                {
                    ColumnModel cmtem = (ColumnModel)datalist[i];
                    if (cmtem.Isstaticpub != 1)
                    {
                        datalist.RemoveAt(i);
                    }
                }
                Repeater1.DataSource = datalist;
                Repeater1.DataBind();
                this.cnavi.Text = cbll.LayeridSysColumnNaiv(Layerid) + cbll.StaticPubLayeridColumnNaiv(layerid, Layerid);
            }
            

        }

    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) {
       HtmlAnchor a= e.Item.FindControl("child") as HtmlAnchor;
       a.HRef += layerid;
    }
    protected void allBtn_click(object sender, EventArgs e)
    {

    }
    protected void modBtn_click(object sender, EventArgs e)
    {

    }



    protected void LinkButton1_Command(object sender, CommandEventArgs e)
    {


        columnId = e.CommandArgument.ToString();

        DataTable dt = BLLArticleInfo.getColumnName(columnId);
        foreach (DataRow row in dt.Rows)
        {
            eName = row["ECLASSNAME"].ToString();
            fileName = row["ColumnFileName"].ToString();
            orderId = row["ORDERID"].ToString();
            if (string.IsNullOrEmpty(fileName) || fileName == "")
            {
                fileName = row["CLASSID"].ToString();
            }
        }

        if (columnId == "196" && orderId == "2")
        {
            url = "http://localhost/allergy/lore/lore.aspx";
        }
        else
        {
            url = "http://localhost/allergy/lore/ArticleList.aspx?columnId=" + columnId + "&classId=" + columnId;
        }

        dpath = HttpContext.Current.Server.MapPath("../../allergy/lore/" + eName);
        if (!Directory.Exists(dpath))
        {
            Directory.CreateDirectory(dpath);
        }
        allpath = dpath +"/"+ fileName+".html";
        GenerateHTML.generateInfoHTML(url, allpath);

    }
}